<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
<script>
   //  将数组中值为 0 的项去掉，将不为 0 的值存入一个新的数组，生成新的数组

   //定义函数
    function noZero(arr){
      var noZero = [];
      for(var i = 0; i< arr.length; i++){
        if(arr[i] != 0){
          noZero.push(arr[i])
        }
      }
      return noZero;
    }

    //执行
    var arr = [1,2,3,4,0,2,3,0,45,23,0,45]
    console.log(noZero(arr));
    
</script>
</html>